package com.ruoyi.project.wechat.controller;

import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.wechat.domain.WxOpenLoginConfig;
import com.ruoyi.project.wechat.service.WxOpenLoginConfigService;
import me.chanjar.weixin.common.util.http.URIUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 微信登录
 */
@RestController
@RequestMapping("/wechat/log")
public class WxLoginController {
    private static final Logger logger = LoggerFactory.getLogger(WxLoginController.class);
    @Resource
    private WxOpenLoginConfigService wxOpenLoginConfigService;

    /**
     * 获取微信PC端登录二维码
     */
    @PreAuthorize("@ss.hasPermi('wechat:login:image')")
    @GetMapping("/getPcImage")
    public AjaxResult getWxLoginImage(){
        String wxLoginImage = wxOpenLoginConfigService.getWxLoginImage();
        return AjaxResult.success(wxLoginImage);
    }

    /**
     * 通过code获取access_token
     */
    @PreAuthorize("@ss.hasPermi('wechat:login:token')")
    @GetMapping("/pcLoginCallBack")
    public AjaxResult getWxAccessToken(String code){
        logger.info("收到pc登陆回调 code = " + code );
        AjaxResult wxAccessToken = wxOpenLoginConfigService.getWxAccessToken(code);

        return null;
    }



}
